package com.yilin.tms.data.controller;

import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.annotation.UserTarget;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.core.commons.annotation.SkipLoginVerify;
import com.yilin.tms.core.commons.utils.ParamUtil;
import com.yilin.tms.core.entity.data.statistics.*;
import com.yilin.tms.core.entity.data.statistics.capital.CapitalStatistics;
import com.yilin.tms.core.entity.data.statistics.order.goods.GoodsStatistics;
import com.yilin.tms.core.entity.data.statistics.order.rob.RobStatistics;
import com.yilin.tms.core.entity.data.statistics.order.transit.TransitStatistics;
import com.yilin.tms.core.entity.data.statistics.truck.VehicleStatistics;
import com.yilin.tms.core.entity.data.statistics.user.HatchStatistics;
import com.yilin.tms.core.entity.data.statistics.user.ShipperStatistics;
import com.yilin.tms.core.entity.data.statistics.user.TruckerStatistics;
import com.yilin.tms.core.entity.data.statistics.user.UserStatistics;
import com.yilin.tms.core.entity.user.UserType;
import com.yilin.tms.core.remote.ICapitalRemote;
import com.yilin.tms.core.remote.IOrderRemote;
import com.yilin.tms.core.remote.IUserRemote;
import com.yilin.tms.core.remote.IVehicleRemote;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 易林云系统
 * 统计中控终端控制器
 */
@RestController
@RequestMapping("/data/statistics/")
public class StatisticsController extends BaseController {

    @Resource
    IUserRemote userRemote;
    @Resource
    IOrderRemote orderRemote;
    @Resource
    IVehicleRemote vehicleRemote;
    @Resource
    ICapitalRemote capitalRemote;


    /**
     * 用户统计
     */
    @PostMapping(value = "getUserStatistics")
    public ReturnData<UserStatistics> getUserStatistics() {

        UserStatistics userStatistics = ParamUtil.isSuccess(userRemote.getUserStatistics());
        return jsonView(true, "获取成功", userStatistics);
    }

    /**
     * 孵化统计
     */
    @PostMapping(value = "getHatchStatistics")
    public ReturnData<HatchStatistics> getHatchStatistics() {

        HatchStatistics hatchStatistics = ParamUtil.isSuccess(userRemote.getHatchStatistics());
        return jsonView(true, "获取成功", hatchStatistics);
    }

    /**
     * 货主统计
     */
    @PostMapping(value = "getShipperStatistics")
    public ReturnData<ShipperStatistics> getShipperStatistics() {

        ShipperStatistics shipperStatistics = ParamUtil.isSuccess(userRemote.getShipperStatistics());
        return jsonView(true, "获取成功", shipperStatistics);
    }

    /**
     * 车主统计
     */
    @PostMapping(value = "getTruckerStatistics")
    public ReturnData<TruckerStatistics> getTruckerStatistics() {
        TruckerStatistics truckerStatistics = ParamUtil.isSuccess(userRemote.getTruckerStatistics());
        return jsonView(true, "获取成功", truckerStatistics);
    }

    /**
     * 货源统计
     */
    @PostMapping(value = "getGoodsStatistics")
    public ReturnData<GoodsStatistics> getGoodsStatistics() {
        GoodsStatistics goodsStatistics = ParamUtil.isSuccess(orderRemote.getGoodsStatistics());
        return jsonView(true, "获取成功", goodsStatistics);
    }

    /**
     * 运单统计
     */
    @PostMapping(value = "getRobStatistics")
    public ReturnData<RobStatistics> getRobStatistics() {
        RobStatistics robStatistics = ParamUtil.isSuccess(orderRemote.getRobStatistics());
        return jsonView(true, "获取成功", robStatistics);
    }

    /**
     * 抢单统计
     */
    @PostMapping(value = "getTransitStatistics")
    public ReturnData<TransitStatistics> getTransitStatistics() {
        TransitStatistics transitStatistics = ParamUtil.isSuccess(orderRemote.getTransitStatistics());
        return jsonView(true, "获取成功", transitStatistics);
    }

    /**
     * 车源统计
     */
    @PostMapping(value = "getVehicleStatistics")
    public ReturnData<VehicleStatistics> getVehicleStatistics() {
        VehicleStatistics vehicleStatistics = ParamUtil.isSuccess(vehicleRemote.getVehicleStatistics());
        return jsonView(true, "获取成功", vehicleStatistics);
    }

    /**
     * 获取今日动态数据
     */
    @PostMapping(value = "getTodayStatistics")
    @SkipLoginVerify
    public ReturnData<Map<String, Object>> getTodayStatistics() {
        Map<String, Object> todayStatistics = ParamUtil.isSuccess(orderRemote.getTodayStatistics());
        return jsonView(SUCCESS_CODE, "获取成功", todayStatistics);
    }

    //---未处理统计区-----

    /**
     * 用户证件未认证 八个
     * 车辆证件未认证 两个
     * 运单流程模块 清算和汇总  预支付单 预退款单 预结算单
     * 财务支付结算 付款记录 收款记录 退款记录
     */
    @PostMapping(value = "getUntreatedStatisticsCollection")
    public ReturnData<UntreatedStatisticsCollection> getUntreatedStatisticsCollection() {
        UntreatedStatisticsCollection untreatedStatisticsCollection = new UntreatedStatisticsCollection();
        //用户证件未认证 八个
        UserNoAuthStatistics userNoAuthStatistics = ParamUtil.isSuccess(userRemote.getUserNoAuthStatistics());
        untreatedStatisticsCollection.setUserNoAuthStatistics(userNoAuthStatistics);
        //车辆证件未认证 两个
        VehicleNoAuthStatistics vehicleNoAuthStatistics = ParamUtil.isSuccess(vehicleRemote.getVehicleNoAuthStatistics());
        untreatedStatisticsCollection.setVehicleNoAuthStatistics(vehicleNoAuthStatistics);
        //运单流程模块 清算和汇总
        OrderStatistics orderStatistics = ParamUtil.isSuccess(orderRemote.getOrderStatistics());
        untreatedStatisticsCollection.setOrderStatistics(orderStatistics);
        //财务支付结算 付款记录 收款记录 退款记录
        TradeRecordStatistics tradeRecordStatistics = ParamUtil.isSuccess(capitalRemote.getTradeRecordStatistics());
        untreatedStatisticsCollection.setTradeRecordStatistics(tradeRecordStatistics);
        return jsonView(true, "获取成功", untreatedStatisticsCollection);
    }

    /**
     * 资金统计
     */
    @PostMapping(value = "getCapitalStatistics")
    public ReturnData<CapitalStatistics> getCapitalStatistics() {
        CapitalStatistics capitalStatistics = ParamUtil.isSuccess(capitalRemote.getCapitalStatistics());
        return jsonView(SUCCESS_CODE, "获取成功", capitalStatistics);
    }


}
